package com.Test;

import java.time.LocalDate;
import java.time.Month;
import java.time.YearMonth;

public class Test28 {
    public static void main(String[] args) {

        // 获取当前日期
        LocalDate today = LocalDate.now();

        // 获取上个月的年份和月份
        YearMonth lastMonth = YearMonth.from(today.minusMonths(1));
        int lastMonthYear = lastMonth.getYear();
        Month lastMonthMonth = lastMonth.getMonth();

        // 上个月的第一天
        LocalDate firstDayOfLastMonth = LocalDate.of(lastMonthYear, lastMonthMonth, 1);

        // 上个月的最后一天
        LocalDate lastDayOfLastMonth = lastMonth.atEndOfMonth();

        // 输出结果
        System.out.println("上个月的第一天：" + firstDayOfLastMonth);
        System.out.println("上个月的最后一天：" + lastDayOfLastMonth);

    }
}
